﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class LoopNodeHandler : BaseNodeHandler
{
    public override BehaviorNodeState ExcuteNode(BehaviorEntity entity, NodeData node)
    {
        SingleBranchNodeData data = (SingleBranchNodeData)node;
        NumTaskData taskData = (NumTaskData)data.TaskArgs;
        if (data.CurNodeState==BehaviorNodeState.Running)
        {
            for (float i = taskData.CurNum; i < taskData.TargetNum; i++)
            {
                GetChildNodeHandler(data.ChildNode.CurNodeType).ExcuteNode(entity, data.ChildNode);
            }
            if (taskData.CurNum>= taskData.TargetNum)
            {
                node.CurNodeState = BehaviorNodeState.Success;
            }
        }
        return node.CurNodeState;
    }

    public override void ResetNode(NodeData node)
    {
        SingleBranchNodeData data = (SingleBranchNodeData)node;
        NumTaskData taskData = (NumTaskData)data.TaskArgs;
        data.CurNodeState = BehaviorNodeState.Running;
        taskData.CurNum = 0;
    }
}